"""
CodeReader.py -- loading method bodies from Bodies.xml.

Contains class which loads the method bodies. Is used by the
Intepretor class from Interpretor.py.
"""

##@package CodeReader
# Contains class which loads the method bodies. Is used by the
# Intepretor class from Interpretor.py.
#
# @author Johan "Solo" Luisier
# @date November 2011

from xml.dom import minidom, Node
from XmlCppClassGenerator.BaseReader import _BaseReader
import codecs

## Class loading the method bodies.
# The predefined method bodies are loaded from
# XmlCppClassGeneratorInfo/Bodies.xml.
#
# Inherits from _BaseReader since the basic functionality is provided
# by this class.
#
# @author Johan "Solo" Luisier
# @date November 2011
class CodeReader( _BaseReader ) :
    ## Constructor
    def __init__( self ) :
        from XmlCppClassGenerator import fullPath
        _BaseReader.__init__( self, fullPath() + "Bodies.xml" )
        if ( not self.checkRootNode( "bodies" ) ) :
            exit( 1 )
        self.__ConsideredBodies = [ "empty",
                                    "stdGetter",
                                    "stdSetter",
                                    "ptrGetter",
                                    "ptrSetter" ]
        self.__Information = {}
        if ( not self._loadElements( self._getXmlDomRoot(), self.__ConsideredBodies, self.__Information ) ) :
            message = "Could not get all the needed information from the xml "
            message += "file, must abort."
            self.error( message )
            exit( 1 )
    ## Allows to access the wanted information about function bodies
    # from the translator instance.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] key key of the wanted information.
    #
    # @return a tuple containing the wanted information and the number
    # of strings to be replaced with format().
    def getInformationBody( self, key ) :
        return self._getInformation( self.__Information, key )
